#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int findPoisonedDuration(vector<int>& t, int duration) {
        int ret = 0;
        int n = t.size();
        for (int i = 1; i < n; i++)
        {
            int x = t[i] - t[i - 1];
            if (t[i] - t[i - 1] < duration) {
                ret += x;
            }
            else {
                ret += duration;
            }
        }
        return ret + duration;
    }
};